package com.quantstack.llcommonlibrary.base;

import java.io.File;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

/**
 * @author wu_ming_zhi_bei
 * @date 2021/2/24 22:37
 * @Notes
 */
public class BaseRepository {

    /**
     * 创建json的RequestBody
     * @param json
     */
    public RequestBody createJsonRequestBody(String json){
        MediaType mediaType=MediaType.Companion.parse("application/json;charset=utf-8");
        return RequestBody.Companion.create(json,mediaType);
    }

    /**
     * 创建json的RequestBody
     * @param
     */
    public MultipartBody createMultipartBody(String custNo, File file,String type,String fileSource){
        MultipartBody.Builder builder = new MultipartBody.Builder();
        builder.addFormDataPart("custNo",custNo);
        builder.addFormDataPart("kycType",type);
        builder.addFormDataPart("fileSource",fileSource);
        MediaType mediaType=MediaType.Companion.parse("image/jpg");
        RequestBody requestBody = RequestBody.Companion.create(mediaType,file);
        builder.addFormDataPart("kycImg", file.getName(), requestBody);
        builder.setType(MultipartBody.FORM);
        return builder.build();
    }
}
